package com.shengxian.basic.mylogin.entity;


import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.teautil.*;
import com.aliyun.teautil.models.*;


public class Sample {

//   static String AccessKeyId="LTAI5tSBNDqaDhtChEHHT8Uc";
//    static String AccessKeySecret="pSObAk9755uAeDUIHuX9oTKJelOdgo";

    static String AccessKeyId="LTAI5t7SEkq6WDLdzkMB1ood";
    static String AccessKeySecret="zYpyFg9wAAtdYNPb9GhS4iEgygpnry";

    /**
     * 使用AK&SK初始化账号Client
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的 AccessKey ID
                .setAccessKeyId(AccessKeyId)
                // 您的 AccessKey Secret
                .setAccessKeySecret(AccessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        System.out.println("1");
        return new com.aliyun.dysmsapi20170525.Client(config);
    }


    public static String maintest(String phone, String[] args_) throws Exception {
        if (phone.length() == 0) {
            phone = "16601273758";
        }
        StringBuilder stringBuilder=new StringBuilder();
        for (int i=0;i<6;i++){
            int s = (int)(Math.random()*10) ;
            stringBuilder.append(s);
        }

        System.out.println("stringBuilder=  " + stringBuilder);
         String num =stringBuilder.toString();
//        String num ="222222";

        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dysmsapi20170525.Client client = Sample.createClient(AccessKeyId,  AccessKeySecret);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName("阿里云短信测试")
                .setTemplateCode("SMS_154950909")
                .setPhoneNumbers(phone)
                .setTemplateParam("{\"code\": " + num + " }");
//                .setTemplateParam("{\"code\":\"1234\"}");
        System.out.println("3");
        RuntimeOptions runtime = new RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            System.out.println("5");
            SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
            System.out.println(" 5.0 内容： " + sendSmsResponse.getHeaders().get("SmsSendDetailDTOs"));
            System.out.println(" 5.0  发送成功  ");
            return num;
        } catch (TeaException error) {
            // 如有需要，请打印 error
            System.out.println("7");
            System.out.println("7 " + error.message);
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            System.out.println("9");
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要，请打印 error
            System.out.println("9 " + error.message);
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
        return null;
    }
}
